//
//  KFWNotificationProblemCell.m
//  KWNLaywerClient
//
//  Created by 孔六五 on 15/1/28.
//  Copyright (c) 2015年 张明磊. All rights reserved.
//

#import "KFWNotificationProblemCell.h"
#import "Model_notificationProblem.h"
#import "UIButton+WebCache.h"

@implementation KFWNotificationProblemCell
@synthesize imageview_line;
@synthesize imageview_message;
@synthesize imageview_ren;
@synthesize imageview_unread;
@synthesize label_name;
@synthesize label_QuestionDetailType;
@synthesize label_QuestionType;
@synthesize label_text;
@synthesize label_time;
@synthesize button_addPhoto;
@synthesize button_photo;

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        imageview_ren = [[UIImageView alloc] initWithFrame:CGRectMake(20, 13, 11, 15)];
        imageview_ren.image = [UIImage imageFileName:@"image_free_Person.png"];
        
        label_name = [UIUtils creatLabel];
        label_name.frame = CGRectMake(imageview_ren.frame.origin.x + imageview_ren.frame.size.width + 3, 13, 140, 15);
        label_name.font = FontOfHelveticaBold(13);
        label_name.textColor = RGB(206, 206, 206);

        imageview_message = [[UIImageView alloc] initWithFrame:CGRectMake(MainScreenWidth - 143, 10, 20, 19)];
        imageview_message.image = [UIImage imageFileName:@"image_qListType.png"];
        
        label_QuestionType = [UIUtils creatLabel];
        label_QuestionType.frame = CGRectMake(MainScreenWidth - 120, 13, 52, 15);
        label_QuestionType.textColor = RGB(134, 177, 217);
        label_QuestionType.font = FontOfHelveticaBold(13);;
        
        label_QuestionDetailType = [UIUtils creatLabel];
        label_QuestionDetailType.frame = CGRectMake(MainScreenWidth - 62, 13, 52, 15);
        label_QuestionDetailType.textColor = RGB(134, 177, 217);
        label_QuestionDetailType.font = FontOfHelveticaBold(13);

        imageview_unread = [[UIImageView alloc] initWithFrame:CGRectMake(6, 45, 8, 8)];
//        imageview_unread.backgroundColor = RGB(219, 15, 31);
        imageview_unread.backgroundColor = [UIColor redColor];
        imageview_unread.hidden = YES;
        imageview_unread.layer.cornerRadius = 4;
        imageview_unread.clipsToBounds = YES;
        
        label_text = [UIUtils creatLabel];
        [label_text sizeToFit];
        label_text.numberOfLines = 0;
        label_text.font = FontOfQuestionList;
        label_text.frame = CGRectMake(20, 40, MainScreenWidth - 30, 20);
        label_text.textColor = ColorOfQuestionList;
        label_text.hidden = YES;
        
        button_photo = [UIButton buttonWithType:UIButtonTypeCustom];
        button_photo.frame = CGRectMake(0, 0, 0, 0);
        button_photo.backgroundColor = [UIColor blackColor];
        button_photo.tag = TagOfView + 1;
        [button_photo.imageView setContentMode:UIViewContentModeScaleAspectFit];
        button_photo.hidden = YES;
        
        button_addPhoto = [UIButton buttonWithType:UIButtonTypeCustom];
        button_addPhoto.backgroundColor = [UIColor blackColor];
        button_addPhoto.frame = CGRectMake(0, 0, 0, 0);
        button_addPhoto.tag = TagOfView + 2;
        [button_addPhoto.imageView setContentMode:UIViewContentModeScaleAspectFit];
        button_addPhoto.hidden = YES;

        label_time = [UIUtils creatLabel];
        label_time.font = FontOfSystem(13);
        label_time.frame = CGRectZero;
        label_time.textColor = RGB(194, 194, 194);
        
        imageview_line = [[UIImageView alloc] initWithFrame:CGRectZero];

        [self addSubview:imageview_ren];
        [self addSubview:label_name];
        [self addSubview:imageview_message];
        [self addSubview:label_QuestionType];
        [self addSubview:label_QuestionDetailType];
        [self addSubview:imageview_unread];
        [self addSubview:label_text];
        [self addSubview:button_photo];
        [self addSubview:button_addPhoto];
        [self addSubview:label_time];
        [self addSubview:imageview_line];

    }
    return self;
}


- (void)changeNotiProblemCellWith:(Model_notificationProblem *)problem
{
    NSInteger kind = problem.string_question_type.integerValue;
    NSArray *arr = [UIUtils getQuestionTypeWithkind:kind];
    label_QuestionType.text = arr[0];
    label_QuestionDetailType.text = arr[1];
    if ([problem.string_isunread integerValue] == 0) {
        imageview_unread.hidden = YES;
        label_text.textColor = RGB(162, 162, 162);
    }
    else
    {
        imageview_unread.hidden = NO;
        label_text.textColor = ColorOfQuestionList;
    }
    
    if (problem.string_content && problem.string_content.length>0) {
        label_text.hidden = NO;
        label_text.text = problem.string_content;
        label_text.frame = CGRectMake(20, 40, MainScreenWidth - 30, 20);
        
        if (problem.arr_contentimg && problem.arr_contentimg.count > 0) {
            button_photo.hidden = NO;
            button_photo.frame = CGRectMake(20, label_text.frame.origin.y + label_text.frame.size.height + 10, 50, 50);
            [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:problem.arr_contentimg[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            
            if (problem.arr_contentimg.count > 1) {
                button_addPhoto.hidden = NO;
                button_addPhoto.frame = CGRectMake(button_photo.frame.origin.x + button_photo.frame.size.width + 5, label_text.frame.origin.y + label_text.frame.size.height + 10, 50, 50);
                [button_addPhoto sd_setBackgroundImageWithURL:[NSURL URLWithString:problem.arr_contentimg[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            }
            
            label_time.frame = CGRectMake(20, button_photo.frame.origin.y + button_photo.frame.size.height + 10, 200, 15);
        }
        else
        {
            button_photo.hidden = YES;
            button_photo.frame = CGRectZero;
            button_addPhoto.hidden = YES;
            button_addPhoto.frame = CGRectZero;
            
            label_time.frame = CGRectMake(20, label_text.frame.origin.y + label_text.frame.size.height + 10, 200, 15);
        }
    }
    else
    {
        label_text.hidden = YES;
        label_text.frame = CGRectMake(20, 40,0, 0);
        
        if (problem.arr_contentimg && problem.arr_contentimg.count > 0) {
            button_photo.hidden = NO;
            button_photo.frame = CGRectMake(20, 40, 50, 50);
            [button_photo sd_setBackgroundImageWithURL:[NSURL URLWithString:problem.arr_contentimg[0]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            
            if (problem.arr_contentimg.count > 1) {
                button_addPhoto.hidden = NO;
                button_addPhoto.frame = CGRectMake(button_photo.frame.origin.x + button_photo.frame.size.width + 5, 40, 50, 50);
                [button_addPhoto sd_setBackgroundImageWithURL:[NSURL URLWithString:problem.arr_contentimg[1]] forState:UIControlStateNormal placeholderImage:[UIImage imageFileName:Default_placeholder]];
            }
            
            label_time.frame = CGRectMake(20, button_photo.frame.origin.y + button_photo.frame.size.height + 10, 200, 15);
        }
        else
        {
            button_photo.hidden = YES;
            button_photo.frame = CGRectZero;
            button_addPhoto.hidden = YES;
            button_addPhoto.frame = CGRectZero;
            
            label_time.frame = CGRectMake(20, 40, 200, 15);
        }
    }
    
    label_time.text = problem.string_time;
    imageview_line.frame = CGRectMake(0, label_time.frame.origin.y + label_time.frame.size.height + 9, MainScreenWidth, 1);
    imageview_line.backgroundColor = RGB(220, 220, 220);

}

@end
